//面试 自己实现strcpy_num
#include <bits/stdc++.h>
using namespace std;
// src  ---------
// dst   ----------
char * strcpy_num2(char *dst, char *src, int nMax) {
  int len1 = strlen(src);
  int len2 = strlen(dst);
  int cnt = std::min(nMax, len2);
  for (int i = cnt-1; i >= 0; ) {
    dst[i] = src[i];
    i--;
  }
  dst[cnt] = '\0';
  return dst;
}
// src    ---------
// dst   ----------
char * strcpy_num(char *dst, char *src, int nMax) {
  int len1 = strlen(src);
  int len2 = strlen(dst);
  int cnt = std::min(nMax, len2);
  for (int i = 0; i < cnt ; ) {
    dst[i] = src[i];
    i++;
  }
  dst[cnt] = '\0';
  return dst;
}

int main() {
  char s1[20] = "abcdef";
  char s2[20] = "123456";

  char *ret = NULL;
  ret = strcpy_num(s2, s1, 7);  printf("%s\n", ret);
  ret = strcpy_num(s1+1, s1, 2);  printf("%s\n", ret);
  printf("\n");
  ret = strcpy_num2(s1+1, s1, 2);  printf("%s\n", ret);
  return 0;
}
